package org.meetunexpectedly.service.video.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.meetunexpectedly.entity.video.VideoShare;
import org.meetunexpectedly.mapper.video.VideoShareMapper;
import org.meetunexpectedly.service.video.VideoShareService;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.stream.Collectors;

/**
 * @Description: 视频分享服务实现类
 * @Author: pupil
 * @Date: 2024/08/22 下午 7:01
 */
@Service
public class VideoShareServiceImpl extends ServiceImpl<VideoShareMapper, VideoShare> implements VideoShareService {


    @Override
    public Boolean share(VideoShare videoShare) {
        try {
            // 利用videoId和ip做为唯一索引,少一次查询,一个ip只能分享一次
            this.save(videoShare);
        } catch (Exception e) {
            return false;
        }
        return true;
    }

    @Override
    public List<Long> getShareUserId(Long videoId) {
        // 根据视频id查询视频分享表，然后筛选出用户id转换成list集合
        return this.list(new LambdaQueryWrapper<VideoShare>().eq(VideoShare::getVideoId, videoId)).stream().map(VideoShare::getUserId).collect(Collectors.toList());

    }
}
